package profile.hujia.profile.elasticsearch.study.service.simulate;

import org.springframework.stereotype.Service;
import profile.hujia.profile.elasticsearch.study.model.SimulateInsertSourceEntity;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * class info
 *
 * @author fuyaqi
 * @date 2019/9/26 13:58
 */
@Service
public class SimulateData {

    private Map<String, String[]> map;

    public List<SimulateInsertSourceEntity> getListData() {
        loadProperties();
        List<SimulateInsertSourceEntity> list = new ArrayList<>();
//        String[] types=map.get("type");
//        String[] kinds=map.get("kind");
//        String[] subjects=map.get("subject");
//        String[] grades=map.get("grade");
//        String[] areas=map.get("area");
//        String[] periods=map.get("period");
//        String[] yearss=map.get("years");
        String[] index1s = map.get("index1");
        String[] index2s = map.get("index2");
        String[] index3s = map.get("index3");
        String[] index4s = map.get("index4");
        String[] index5s = map.get("index5");
        String[] index6s = map.get("index6");
        String[] index7s = map.get("index7");
        String[] index8s = map.get("index8");
        String[] index9s = map.get("index9");
        String[] index10s = map.get("index10");
        String[] index11s = map.get("index11");
        String[] index12s = map.get("index12");
        String[] index13s = map.get("index13");
        String[] index14s = map.get("index14");
        String[] index15s = map.get("index15");
        String[] index16s = map.get("index16");
        String[] index17s = map.get("index17");
        String[] index18s = map.get("index18");
        String[] index19s = map.get("index19");
        String[] index20s = map.get("index20");
        String[] index21s = map.get("index21");
        String[] index22s = map.get("index22");
        String[] index23s = map.get("index23");
        String[] index24s = map.get("index24");
        int counter = 1;
        for (String index1 : index1s) {
            for (String index2 : index2s) {
                for (String index3 : index3s) {
                    for (String index4 : index4s) {
                        for (String index5 : index5s) {
                            for (String index6 : index6s) {
                                for (String index7 : index7s) {
                                    for (String index8 : index8s) {
                                        for (String index9 : index9s) {
                                            for (String index10 : index10s) {
                                                for (String index11 : index11s) {
                                                    for (String index12 : index12s) {
                                                        for (String index13 : index13s) {
                                                            for (String index14 : index14s) {
                                                                for (String index15 : index15s) {
                                                                    for (String index16 : index16s) {
                                                                        for (String index17 : index17s) {
                                                                            for (String index18 : index18s) {
                                                                                for (String index19 : index19s) {
                                                                                    for (String index20 : index20s) {
                                                                                        for (String index21 : index21s) {
                                                                                            for (String index22 : index22s) {
                                                                                                for (String index23 : index23s) {
                                                                                                    for (String index24 : index24s) {
                                                                                                        SimulateInsertSourceEntity sourceEntity = new SimulateInsertSourceEntity();
                                                                                                        String title = "title" + counter;
                                                                                                        sourceEntity.setTitle(title);
                                                                                                        sourceEntity.setIndex1(index1);
                                                                                                        sourceEntity.setIndex2(index2);
                                                                                                        sourceEntity.setIndex3(index3);
                                                                                                        sourceEntity.setIndex4(index4);
                                                                                                        sourceEntity.setIndex5(index5);
                                                                                                        sourceEntity.setIndex6(index6);
                                                                                                        sourceEntity.setIndex7(index7);
                                                                                                        sourceEntity.setIndex8(index8);
                                                                                                        sourceEntity.setIndex9(index9);
                                                                                                        sourceEntity.setIndex10(index10);
                                                                                                        sourceEntity.setIndex11(index11);
                                                                                                        sourceEntity.setIndex12(index12);
                                                                                                        sourceEntity.setIndex13(index13);
                                                                                                        sourceEntity.setIndex14(index14);
                                                                                                        sourceEntity.setIndex15(index15);
                                                                                                        sourceEntity.setIndex16(index16);
                                                                                                        sourceEntity.setIndex17(index17);
                                                                                                        sourceEntity.setIndex18(index18);
                                                                                                        sourceEntity.setIndex19(index19);
                                                                                                        sourceEntity.setIndex20(index20);
                                                                                                        sourceEntity.setIndex21(index21);
                                                                                                        sourceEntity.setIndex22(index22);
                                                                                                        sourceEntity.setIndex23(index23);
                                                                                                        sourceEntity.setIndex24(index24);
                                                                                                        sourceEntity.setCreateTime(new Date());
                                                                                                        list.add(sourceEntity);
                                                                                                        counter++;
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return list;
    }


    private void loadProperties() {
        Map<String, String[]> map = new HashMap();
        try {
            //加载测试数据
            InputStreamReader inputStream = new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("testData.properties"), "UTF-8");
            Properties pro = new Properties();
            pro.load(inputStream);
            for (Object key : pro.keySet()) {
                String keyStr = key.toString();
                String title = pro.getProperty(keyStr);
                String[] titles = title.split(",");
                map.put(keyStr, titles);
            }
        } catch (FileNotFoundException e) {
            System.out.println("properties文件路径有误！");
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.map = map;
    }
}
